<template>
  <div class="tabbar-item-class" @click="tabbarItemClick">
    <div>
      <slot v-if="isAction" name="icon"></slot>
      <slot v-else="isAction" name="icon-active"></slot>
    </div>
    <div class="title" :style="activeColorSelect()">
      <slot name="title"></slot>
    </div>
  </div>
</template>

<script>
  export default {
    name: "TabbarItem",
    props:{
      path:{
        type:String
      },
      activColor:{
        type: String
      }
    },
    data:function () {

      return {
        titleColor:'#000'
      }
    },
    computed:{

      isAction:function () {
        // 监听 $route 的改变
        return this.$route.path.indexOf(this.path) == -1
      }
    },
    methods:{
      tabbarItemClick(){

          if (this.$route.path.indexOf(this.path) == -1){
            this.$router.push(this.path)
          }
      },
      activeColorSelect(){

        // console.log('111');
        return {
          'color':this.isAction?this.titleColor:this.activColor
        }
      }
    }
  }
</script>

<style scoped>
  .tabbar-item-class{

    flex-grow: 1;
    text-align: center;
    font-size: 14px;
  }
  .tabbar-item-class .title{

  }
  .tabbar-item-class img{
    width: 24px;
    height: 24px;
    vertical-align: middle;
    margin-top: 3px;
    margin-bottom: 1px;
  }
</style>
